using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

using YEngineLib.Audio;
using YEngineLib.Graphics;
using YEngineLib.Input;
using YEngineLib.State;
using YEngineLib.Time;
using YEngineLib.YYRandom;
using YEngineLib.YYMath;
using YEngineLib.Animation;

using YEngineLib.HighScores;

namespace YEngineLib
{
    public static class YEngine
    {
        static Game game = null;

        public static Game Game
        {
            get { return game; }
        }

        static YTime time = null;

        public static YTime Time
        {
            get { return time; }
        }

        static YAudioManager audio = null;

        public static YAudioManager Audio
        {
            get { return audio; }
        }

        static YGraphics graphics = null;

        public static YGraphics Graphics
        {
            get { return graphics; }
        }

        static YRandom random = null;

        public static YRandom Random
        {
            get { return random; }
        }

        static YMath math = null;

        public static YMath Math
        {
            get { return math; }
        }

        static YInputManager input = null;

        public static YInputManager Input
        {
            get { return input; }
        }

        static YHighScores highScores = null;

        public static YHighScores HighScores
        {
            get { return highScores; }
        }

        static YGameStateManager gameStateManager = null;

        public static YGameStateManager State
        {
            get { return gameStateManager; }
        }

        static YAnimationLoader animLoader = null;

        public static YAnimationLoader Animation
        {
            get { return animLoader; }
        }

        public static bool Initialize(Game game, GraphicsDeviceManager graphicsDeviceManager)
        {
            YEngine.game = game;

            time = new YTime();

            audio = new YAudioManager();
            audio.Initialize(game);

            graphics = new YGraphics();
            graphics.Initialize(graphicsDeviceManager);

            highScores = new YHighScores();

            random = new YRandom();

            math = new YMath();

            input = new YInputManager();

            gameStateManager = new YGameStateManager();

            animLoader = YAnimationLoader.Instance;

            return true;
        }

        public static void Update(GameTime gameTime)
        {
            input.ReadDeviceStates();

            time.GameTime = gameTime;

            gameStateManager.Update(time.RealDeltaTime);
        }

        public static void Draw(GameTime gameTime)
        {
            time.GameTime = gameTime;

            gameStateManager.Draw();
        }
    }
}

